import Request from '@/utils/request'
import Cookies from '@/utils/auth'

const state = () => ({
	nftdDetail: {},
	sellMyType:1 // 1我发起的拍卖，2我参与的拍卖，3我发起的值售，4我购买的直售
})
const getters = {
	
}
const mutations = {
	set_nftdDetail: (state, data) => {
		state.nftdDetail = data
	},
	set_sellMyType: (state, data) => {
		state.sellMyType = data
	},
}
const actions = {
	async get_sell_list({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/trade/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
    async get_sell_detail({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/trade/getDetail',params)
			.then(res=>{
                if(res.data.success){
					commit('set_nftdDetail',res.data.data)
				}
				resolve(res.data) 
			})
		})
	},
	// async auction_bid({commit}, params) {   // 拍卖出价
	// 	return new Promise((resolve,reject)=>{
	// 		Request.post('/api/trade/bid',params)
	// 		.then(res=>{
	// 			resolve(res.data) 
	// 		})
	// 	})
	// },
	async get_auction_bid_record({commit}, params) {   // 拍卖出价记录
		return new Promise((resolve,reject)=>{
			Request.post('/api/trade/bidLogList',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async camcel_sale({commit}, params) {   // 取消出售
		return new Promise((resolve,reject)=>{
			Request.post('/api/trade/cancel',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async camcel_auction({commit}, params) {   // 取消拍卖
		// return new Promise((resolve,reject)=>{
		// 	Request.post('/api/trade/cancel',params)
		// 	.then(res=>{
		// 		resolve(res.data) 
		// 	})
		// })
	},
	async get_my_sell_list({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/trade/listMy',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_list_statistics({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/trade/listStatistics',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
}

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
